package com.example.lp.lpmvvm.one.view;

import android.content.Context;
import android.databinding.BindingAdapter;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.lp.lpglide.LpGlide;
import com.example.lp.lpglide.Request.RequestListener;
import com.example.lp.lpmvp.R;
import com.example.lp.lpmvp.databinding.PictureViewBinding;
import com.example.lp.lpmvvm.one.viewmodel.PictureModelView;

/**
 * Author by lp,on 2021/6/15/015,17:44.
 */
public class PictureView extends BaseMvvmView<PictureModelView, PictureViewBinding> {
    private static String TAG = "PictureView";

    public PictureView(Context context) {
        super(context);
        init();
    }

    private void init() {
        getView().findViewById(R.id.tv_title).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick: ");
            }
        });
    }

    @Override
    protected void setDataToView(PictureModelView viewModel) {
        getDataBinding().setPicData(viewModel);
    }

    @Override
    protected int getViewLayoutId() {
        return R.layout.picture_view;
    }

    @Override
    protected void RootClick(View view) {
        Log.i(TAG, "RootClick: ");

    }

    @BindingAdapter("app:imageUrl")
    public static void loadImage(ImageView imageView, String url) {
        LpGlide.with(imageView.getContext()).load(url)
                .loading(com.example.lp.lpglide.R.mipmap.ic_launcher)
                .listener(new RequestListener() {
                    @Override
                    public boolean onSuccess(Bitmap bitmap) {
                        Log.i(TAG, "onSuccess: ");
                        return false;
                    }

                    @Override
                    public boolean onFailure() {
                        return false;
                    }
                }).Into(imageView);
    }
}
